<template>
  <div class="wrap">
    <div class="commonInput">
      <div class="icon" @click='_handleShowComment'></div>
      <input class='inputs' type="text" v-model='commentCont' placeholder='Uh…'>
      <div class="sent" @click='_handleSentComment'></div>
    </div>
  </div>
</template>

<script>
  import { mapGetters, mapActions } from 'Vuex'
  import api from '../../plugins/api'
  import { Toast } from 'mint-ui'

  const Cookie = process.browser ? require('js-cookie') : undefined
  export default {
    data() {
      return {
        commentCont: ''
      }
    },
    props: ['commentData'],
    computed: {
      ...mapGetters([
        'commentList'
      ])
    },
    methods: {
      ...mapActions({
        _handleShowComment: '_isShowComment'
      }),

      // 发表评论
      async _handleSentComment() {
        console.log(typeof (this.commentList))
        if (this.commentCont.length == 0) {
          return false
        }
        const params = {
          sid: Cookie.get('sid'),
          user_id: this.commentData.user_id,
          tag_id: this.commentData.tag_id,
          content: this.commentCont
        }
        const res = await api.setComment(params)
        if (res.status == 0) {
          const data = res.data[0]
          data.ctime = data.ctime * 1000
          this.commentList.comment_num = this.commentList.comment_num + 1
          this.commentList.list.unshift(data)
          this.$store.commit('_setcommentList', this.commentList)
        } else {
          Toast(res.info)
        }
      }
    },
    watch: {
      commentCont: function(curr, old) {
        // console.log(curr)
      }
    }

  }
</script>
<style lang="scss">
  .wrap {
    width: 100%;
    position: absolute;
    z-index: 5;
    background: #ffffff;
    left: 0;
    bottom: 0;
    height: 112px;
    border-radius: 0 0 48px 48px;

    .commonInput {
      height: 112px;

      border-top: 1px solid rgba(0, 0, 0, .1);
      width: 100%;
      display: flex;
      align-items: center;
      padding: 0 20px 0 38px;

      .icon {
        width: 32px;
        height: 32px;
        background: url("../../assets/images/6.png") no-repeat center;
        background-size: 100%;
      }

      .inputs {
        flex-grow: 1;
        height: 80px;
        line-height: 80px;
        background: rgba(237, 240, 240, 1);
        border-radius: 40px;
        margin: 0 24px;
        border: none;
        padding: 0 10px;
        font-size: 28px;
      }

      .sent {
        width: 45px;
        height: 45px;
        background: url("../../assets/images/5.png") no-repeat center;
        -webkit-background-size: 100%;
        background-size: 100%;
      }
    }
  }

</style>
